package com.bw.unit6

import android.content.Intent
import android.os.CountDownTimer
import android.text.TextUtils
import android.widget.ImageView
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.bumptech.glide.Glide
import com.bw.unit3.base.BaseActivity
import com.bw.unit6.databinding.ActivityWelcomeBinding
import com.bw.unit6.viewmodel.LoginViewModel

/**
 *
 * @ClassName: WelcomeActivity
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/13 2:51 PM
 * @Version: 1.0
 */

class WelcomeActivity :
    BaseActivity<LoginViewModel, ActivityWelcomeBinding>(R.layout.activity_welcome) {

    private var countDownTimer: CountDownTimer? = null
    override fun initData() {

    }

    override fun initView() {
        //点击跳过
        dataBinding.tvStip.setOnClickListener {
            startActivity(Intent(this@WelcomeActivity, LoginActivity::class.java))
        }


        //倒计时
        countDownTimer = object : CountDownTimer(2000, 1000) {
            override fun onTick(p0: Long) {
                //每间隔1s执行一次
                dataBinding.tvStip.text = "${p0 / 1000}S后跳转"
            }

            override fun onFinish() {
                //执行完成
                //如果没有登录，跳转到登录页面-LoginActivity
                //如果已经登录跳转到主页面-MainActivity


                ARouter.getInstance()
                    .build("/main/MainActivity")
                    .navigation()

//                if (!TextUtils.isEmpty(SPUtils.getInstance().getString("token"))){
//                    //果已经登录跳转到主页面-MainActivity
//                    ARouter.getInstance()
//                        .build("/main/MainActivity")
//                        .navigation()
//                }else{
//                    ARouter.getInstance()
//                        .build("/login/123")
//                        .withString("userName", "zhangsan")
//                        .navigation()
//                }
                finish()

            }
        }
        //开始倒计时
        countDownTimer?.start()
    }

    override fun onDestroy() {
        super.onDestroy()
        countDownTimer?.cancel()
    }
}